<?php
function createItemHtml($menu)
{
  $submenus = $menu->sub_button ?? [];
  $submenuhtml = '';
if (!empty($submenus)) {
  $submenuhtml = '<ol class="dd-list">';
  foreach ($submenus as $submenu) {
    $submenuhtml = $submenuhtml . createItemHtml($submenu);
  }
  $submenuhtml = $submenuhtml . '</ol>';
}
$key = $menu->key ?? '';
  $html = <<<HTML
<li class="dd-item" data-name="{$menu->name}" data-url="{$menu->url}" data-type="{$menu->type}" data-key="{$key}">
<div class="dd-handle">
  <span class="title">{$menu->name}</span> | {$menu->url}{$key}
  <div class="pull-right action-buttons">
    <a class="brown edit" href="#"><i class="icon-pencil bigger-130"></i></a>
    <a class="blue add" href="#"><i class="icon-plus bigger-130"></i></a>
    <a class="red trash" href="#"><i class="icon-trash bigger-130"></i></a>
  </div>
</div>
{$submenuhtml}
</li>
HTML;
  return $html;
}
function smarty_function_html_wechatmenu($params, $template)
{
  $menus = $params['menus'] ?? [];
  $output = '';
  foreach ($menus as $menu) {
    $output = $output . createItemHtml($menu);
  }
  return $output;
  // return '<ul class="pagination' . $className . '">' . $output . '</ul>';
}

